<template>
  <el-card class="message-main" shadow="never">
    <div id="message-title">
      <p class="message-title-content">
        有什麽想説的？<br />有什麽想問的？<br />有什麽想吐槽的？<br />可以在下面留言...<br />
      </p>
    </div>
    <DividerHr />
    <div class="message-container">
      <p class="message-header">
        <i class="el-icon-third-liuyanban is-vertical" />
        <span>留言</span>
      </p>
      <Markdown />
      <div class="message-footer">
        <p class="no-message" v-if="messages.length <= 0">快来留言吧~</p>
        <div v-else>
          <p class="message-total">
            <span>{{ messages.length }}</span>
            条留言
          </p>
          <ul class="message-list">
            <li v-for="item of messages" :key="item.messageId">
              <CommentItem :message="item" />
            </li>
          </ul>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script>
import $api from "$api/messages";
import DividerHr from "$components/DividerHr";
import Markdown from "$components/editor/Markdown";
import CommentItem from "$components/CommentItem";
export default {
  name: "MessageMain",
  components: {
    DividerHr,
    Markdown,
    CommentItem,
  },
  data() {
    return {
      messages: [],
    };
  },
  mounted() {
    this.getMessages();
  },
  methods: {
    getMessages() {
      $api.getMessages().then((res) => {
        if (res.status === 200) {
          this.messages = res.data;
        }
      });
    },
  },
};
</script>

<style lang="stylus" scoped>
.message-title-content {
  text-align: center;
  font-size: 0.24rem;
  font-weight: 700;
  line-height: 2;
}

.message-header {
  display: flex;
  padding-bottom: 0.1rem;
}

.message-header span {
  color: var(--fontLevel1);
  font-size: 0.2rem;
  font-weight: bold;
}

.message-header i[class*="el-icon-third-"] {
  color: var(--fontLevel1);
  font-size: 0.3rem;
  margin-right: 0.05rem;
}

.no-message {
  color: #555;
  text-align: center;
  padding: 0.2rem 0;
}

.message-total {
  font-size: 0.25rem;
  font-weight: bold;
  padding: 0.2rem 0;
}
</style>